package edu.sdjzu.exam.mapper;


import edu.sdjzu.exam.domain.auth.Permission;
import edu.sdjzu.exam.domain.auth.RolePermission;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RolePermissionMapper {
    @Insert("INSERT INTO Role_Permissions (role_id, permission_id) VALUES (#{roleId}, #{permissionId})")
    @Options(useGeneratedKeys = true, keyProperty = "rolePermissionId")
    void insert(RolePermission rolePermission);

    @Delete("DELETE FROM Role_Permissions WHERE role_id = #{roleId} AND permission_id = #{permissionId}")
    void delete(Long roleId, Long permissionId);

    @Select("SELECT p.* FROM Permissions p JOIN Role_Permissions rp ON p.permission_id = rp.permission_id WHERE rp.role_id = #{roleId}")
    List<Permission> findPermissionsByRoleId(Long roleId);
}
